package top.yaofengqiao.springcloudsimple.auth.biz.domain.auth.service.factory;

import org.springframework.stereotype.Service;
import top.yaofengqiao.springcloudsimple.auth.biz.domain.auth.model.valobj.Oauth2Type;
import top.yaofengqiao.springcloudsimple.auth.biz.domain.auth.service.IOauth2Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


/**
 * @author yfq
 * @date 2024/6/11 13:51
 * @description
 */
@Service
public class DefaultOauth2ServiceFactory implements IOauth2ServiceFactory {
    private final Map<Oauth2Type, IOauth2Service> oauth2ServiceMap = new ConcurrentHashMap<>();
    @Resource
    private IOauth2Service aliPayOauth2Service;
    @Resource
    private IOauth2Service weChatOauth2Service;

    @PostConstruct
    public void init() {
        oauth2ServiceMap.put(Oauth2Type.ALIPAY, aliPayOauth2Service);
        oauth2ServiceMap.put(Oauth2Type.WE_CHAT, weChatOauth2Service);
    }

    @Override
    public IOauth2Service getOauth2Service(Oauth2Type oauth2Type) {
        return oauth2ServiceMap.get(oauth2Type);
    }
}
